cards = [
    {'name': '李四', 'tel': '17715154242', 'job': 'CEO'},  # 字典
]
def main():
    # 用户根据编号选择功能
    while True:
        code = input('请选择功能[1添加|2显示|3修改|4删除|退出(其他)]:')
        if code == '1':
            # 　添加
            add()
        elif code == '2':
            show()
        elif code == '3':
            edit()
        elif code == '4':
            delete()
        else:
            break


def add():
    # 添加功能
    # 1 接收用户输入
    name = input('name:')
    tel = input('tel:')
    job = input('job:')
    # 2 组装为字典
    dict1 = {'name': name, 'tel': tel, 'job': job}
    # 3 添加到列表
    # list.insert() #　指定下标添加元素
    # list.append() # 将整个数据添加到列表末尾
    # list.extend() # 将序列中的元素依次添加到列表末尾
    cards.append(dict1)
    print(cards)
    print('添加成功')


def show():
    # 列表和字典的遍历
    # for info in cards:
    #     for key,value in info.items():
    #         print(f'{key} : {value}', end='|\t')
    #     print()
    print(cards)


def edit():
    # 　修改
    name = input('name:')
    for info in cards:
        if info['name'] == name:
            info['tel'] = input('tel:')
            info['job'] = input('job:')
    print(cards)


def delete():
    # 删除
    name = input('name:')
    for info in cards:
        if info['name'] == name:
            cards.remove(info)
    print(cards)


main()




